package com.esm.sm800.activity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.esm.sm800.R;
import com.esm.sm800.database.dbmodel.Member;
import com.esm.sm800.database.manager.MemberCenter;
import com.esm.sm800.database.manager.SystemCenter;
import com.esm.sm800.util.ZazManager;

import zuo.biao.library.base.BaseActivity;

//指纹录入
public class ZwlrActivity extends BaseActivity implements View.OnClickListener {

    private final String TAG = "ZwlrActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_zwlr);

        m_txtStatus = (TextView) findViewById(R.id.txtStatus);
        m_FpImageViewer = (ImageView) findViewById(R.id.imvImgViewer);
        findViewById(R.id.tv_ok).setOnClickListener(this);
        findViewById(R.id.tv_cancel).setOnClickListener(this);

        if (SystemCenter.getInstance().memberEdit == null) {
            finish();
            return;
        }
        int userID = Math.toIntExact(SystemCenter.getInstance().memberEdit.getId());

        ZazManager.getInstance().m_txtStatus = m_txtStatus;
        ZazManager.getInstance().m_FpImageViewer = m_FpImageViewer;
        ZazManager.getInstance().m_nUserID = userID;
        ZazManager.getInstance().mNeedbreak = false;
        ZazManager.getInstance().mHandler = mHandler;
        ZazManager.getInstance().enroll();
    }

    TextView m_txtStatus;
    ImageView m_FpImageViewer;

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.tv_ok:
                finish();
                break;
            case R.id.tv_cancel:
                finish();
                break;
        }
    }

    Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == ZazManager.FINISH_SB) {
                finishLR();
            }
        }
    };

    private void finishLR() {
        ZazManager.getInstance().mNeedbreak = true;
        SystemCenter.getInstance().memberEdit.setZhiwen(SystemCenter.getInstance().memberEdit.getId() + "");
        setResult(RESULT_OK);
        finish();
    }

    protected void onResume() {
        super.onResume();
        ZazManager.getInstance().m_txtStatus = m_txtStatus;
        ZazManager.getInstance().m_FpImageViewer = m_FpImageViewer;
        ZazManager.getInstance().mHandler = mHandler;
    }

    @Override
    protected void onPause() {
        super.onPause();
        ZazManager.getInstance().m_txtStatus = null;
        ZazManager.getInstance().m_FpImageViewer = null;
        ZazManager.getInstance().mHandler = null;
        ZazManager.getInstance().mNeedbreak = true;
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {

    }

    @Override
    public void initEvent() {

    }
}

